/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.config.javabeans;

/**
 * Class corresponding to the "attribute" element of the exports_conf.xml file.
 */
public class JBAttribute implements java.io.Serializable
{
    /** Name of the attribute to display. */
    private String name = null;

    /** Name of the attribute in the resource. */
    private String value = null;

    /** Type. */
    private String type = null;

    /** Mode. */
    private String mode = null;

    /** Separator. */
    private String separator = null;

    /** Type for multi-valued attribute. */
    private static final String TYPE_MULTI = "multi";

    /** Mode value for the line representation. */
    public static final String MODE_LINES = "lines";

    /** Mode value for the column representation. */
    public static final String MODE_COLS = "cols";

    /** Mode value for the cell representation. */
    public static final String MODE_CELL = "cell";


    /**
     * Gets the name.
     *
     * @return The name.
     */
    public String getName()
    {
        return name;
    }

    /**
     * Sets the name.
     *
     * @param aname  The name to set.
     */
    public void setName(String aname)
    {
        this.name = aname;
    }

    /**
     * Gets the value.
     *
     * @return The value.
     */
    public String getValue()
    {
        return value;
    }

    /**
     * Sets the value.
     *
     * @param avalue  The value to set.
     */
    public void setValue(String avalue)
    {
        this.value = avalue;
    }

    /**
     * Gets the type.
     *
     * @return The type.
     */
    public String getType()
    {
        return type;
    }

    /**
     * Indicates if the attribute is multi-valued.
     *
     * @return true if the attributeis multi-valued.
     */
    public boolean isMultiType()
    {
        return ((type.toLowerCase()).equals(TYPE_MULTI));
    }

    /**
     * Sets the type.
     *
     * @param atype  The type to set.
     */
    public void setType(String atype)
    {
        this.type = atype;
    }

    /**
     * Gets the mode.
     *
     * @return The mode.
     */
    public String getMode()
    {
        return mode;
    }

    /**
     * Indicates if the attribute mode is line.
     *
     * @return true if the mode is line, false otherwise
     */
    public boolean isLineMode()
    {
        if (mode != null)
        {
            return ((mode.toLowerCase()).equals(MODE_LINES));
        }
        return false;
    }

    /**
     * Indicates if the attribute mode is column.
     *
     * @return true if the mode is column, false otherwise
     */
    public boolean isColumnMode()
    {
        if (mode != null)
        {
            return ((mode.toLowerCase()).equals(MODE_COLS));
        }
        return false;
    }

    /**
     * Sets the mode.
     *
     * @param amode  The mode to set.
     */
    public void setMode(String amode)
    {
        this.mode = amode;
    }

    /**
     * Gets the separator.
     *
     * @return The separator.
     */
    public String getSeparator()
    {
        return separator;
    }

    /**
     * Sets the separator.
     *
     * @param asep  The separator to set.
     */
    public void setSeparator(String asep)
    {
        this.separator = asep;
    }


    /**
     * Gets the String representation of the object.
     *
     * @return The String representation.
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();

        buf.append("name = ");
        buf.append(name);
        buf.append(System.getProperty("line.separator"));
        buf.append("value = ");
        buf.append(value);
        buf.append(System.getProperty("line.separator"));
        buf.append("type = ");
        buf.append(type);
        buf.append(System.getProperty("line.separator"));
        buf.append("mode = ");
        buf.append(mode);
        buf.append(System.getProperty("line.separator"));
        buf.append("separator = ");
        buf.append(separator);
        buf.append(System.getProperty("line.separator"));

        return buf.toString();
    }

}
